//
//  MCOtherPersonViewController.m
//  MicroChat
//
//  Created by Mac on 2018/5/30.
//  Copyright © 2018年 stoneobs.qq.com. All rights reserved.
//

#import "MCMineInfoViewController.h"
#import "MCPersonalViewController.h"
@interface MCMineInfoViewController ()

@end

@implementation MCMineInfoViewController


#pragma mark --vc 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人信息";
    self.userModel = STUserManger.defult.loginedUser;
    [self configSubView];
    [self confimBootomView];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [TMUtils sendMyInfoRequestWithHandle:^(MCUserModel *user) {
        self.userModel = user;
        [self configSubView];
    }];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    self.title = self.userModel.user_nick;
    
    self.tableView.backgroundColor = UIColor.whiteColor;
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 10)];
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 180)];
    [imageView sd_setImageWithURL:MCRealImageUrl(self.userModel.user_icon) completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    [header addSubview:imageView];
    
    UIVisualEffectView * visuView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    visuView.frame = imageView.bounds;
    [imageView addSubview:visuView];
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(20, imageView.bottom + 10, 60, 60)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:30
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:nil];
    [header addSubview:iconButton];
    [iconButton sd_setBackgroundImageWithURL:MCRealImageUrl(self.userModel.user_icon) forState:UIControlStateNormal];
    
    STLabel * nickLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right + 15, iconButton.top + 10, 200, 20)
                                                    text:self.userModel.user_nick
                                               textColor:FirstTextColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [header addSubview:nickLable];
    
    STLabel * idLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right + 15, nickLable.bottom + 10, 200, 20)
                                                  text:self.userModel.user_name
                                             textColor:FirstTextColor
                                                  font:15
                                           isSizetoFit:NO
                                         textAlignment:NSTextAlignmentLeft];
    [header addSubview:idLable];
    
    STLabel * areadesLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.left, iconButton.bottom + 20, UIScreenWidth - 30, 20)
                                                       text:@"地区"
                                                  textColor:ThirdTextColor
                                                       font:14
                                                isSizetoFit:NO
                                              textAlignment:NSTextAlignmentLeft];
    [header addSubview:areadesLable];
    
    
    STLabel * areaLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.left, areadesLable.bottom + 20, UIScreenWidth - 30, 20)
                                                    text:[NSString stringWithFormat:@"%@ %@",self.userModel.province,self.userModel.city]
                                               textColor:FirstTextColor
                                                    font:16
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [header addSubview:areaLable];
    
    header.height = areaLable.bottom  + 49;
    
    
    STLabel * genderdesLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.left, areaLable.bottom + 20, UIScreenWidth - 30, 20)
                                                       text:@"性别"
                                                  textColor:ThirdTextColor
                                                       font:14
                                                isSizetoFit:NO
                                              textAlignment:NSTextAlignmentLeft];
    [header addSubview:genderdesLable];
    
    NSString * genderStr = @"男";
    if (!self.userModel.sex.integerValue) {
        genderStr = @"女";
    }
    STLabel * genderLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.left, genderdesLable.bottom + 20, UIScreenWidth - 30, 20)
                                                         text:genderStr
                                                    textColor:FirstTextColor
                                                         font:14
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentLeft];
    [header addSubview:genderLable];
    
    
    header.height = genderLable.bottom + 20;
    self.tableView.tableHeaderView = header;
    [self.tableView reloadData];
}
- (void)confimBootomView{
    STButton * addButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 49)
                                                     title:@"编辑资料"
                                                titleColor:UIColor.whiteColor
                                                 titleFont:16
                                              cornerRadius:0
                                           backgroundColor:TM_ThemeBackGroundColor
                                           backgroundImage:nil
                                                     image:nil];
    addButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    addButton.bottom = TMUtils.tabBarTop + 49;
    [self.view addSubview:addButton];
    __weak typeof(self) weakSelf =  self;
    [addButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedBootomButton:sender];
    }];
    
}
#pragma mark --Action Method
- (void)onSelctedBootomButton:(UIButton*)sender{
    if ([sender.currentTitle isEqualToString:@"编辑资料"]) {
        DDLogInfo(@"点击了 编辑资料");
        MCPersonalViewController * vc =   MCPersonalViewController.new;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
@end

